package com.itheima.service.impl;

import com.itheima.domain.Employee;
import com.itheima.domain.EmployeeExample;
import com.itheima.mapper.EmployeeMapper;
import com.itheima.service.EmployeeService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

/**
 * @author
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 根据id查找一个员工的全部信息
     * @return
     */
    @Override
    public Employee findOneByIdWithEandD(Integer id) {
        return employeeMapper.selectByPrimaryKeyWithDept(id);
    }

    /**
     * 插入一个员工的信息
     * @param employee
     */
    @Override
    public void insert(Employee employee) {
            employeeMapper.insert(employee);
    }

    /**
     * 根据id删除用户
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
    }

    /**
     * 查询所有用户信息
     * @return
     */
    @Override
    public List<Employee> findAll() {
        return employeeMapper.selectByExampleWithDept(null);
    }

    /**
     * 根据用户的id更新数据
     * @param employee
     */
    @Override
    public void updateEmpById(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

    /**
     * 根据id数组来删除用户
     * @param ids
     */
    @Override
    public void deleteEmpsByIds(Integer[] ids) {
        for (Integer id : ids) {
            employeeMapper.deleteByPrimaryKey(id);
        }
    }

}
